$(document).ready(function(){

	var baseurl = $('#baseurl').val();
	$("#mlme-camera").webcam({
        width: 320,
        height: 240,
        mode: "callback",
        swffile: baseurl+"/assets/js/webcam/jscam_canvas_only.swf",
        onTick: function(remain) {
		    if (0 == remain) {
		        jQuery("#cam-status").text("Cheese!");
		    } else {
		        jQuery("#cam-status").text(remain + " seconds remaining...");
		    }
		},
        onSave: function(data) {
			//alert(data);
		    var col = data.split(";");
		    var img = image;

		    for(var i = 0; i < 320; i++) {
		        var tmp = parseInt(col[i]);
		        img.data[pos + 0] = (tmp >> 16) & 0xff;
		        img.data[pos + 1] = (tmp >> 8) & 0xff;
		        img.data[pos + 2] = tmp & 0xff;
		        img.data[pos + 3] = 0xff;
		        pos+= 4;
		    }

		    if (pos >= 4 * 320 * 240) {
		        ctx.putImageData(img, 0, 0);
		        pos = 0;
		    }
		},
        onCapture: function () {
	        jQuery("#flash").css("display", "block");
	        jQuery("#flash").fadeOut("fast", function () {
	                jQuery("#flash").css("opacity", 1);
	        });

	        var d = webcam.save(baseurl+"/assets/js/webcam/upload.php");
	        alert(d);
		},
        debug: function() {},
        onLoad: function() {
		    var cams = webcam.getCameraList();
		    for(var i in cams) {
		        jQuery("#cams").append("<li>" + cams[i] + "</li>");
		    }
		},
		debug: function (type, string) {
	        $("#cam-status").html(type + ": " + string);
		}
	});





});

